package com.lening.controller;

import com.lening.pojo.TbItemCat;
import com.lening.sellergoods.service.ItemCatService;
import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("itemCat")
public class ItemCatController {

    @Resource
    private ItemCatService itemCatService;


    @RequestMapping("findPageBypid")
    public PageResult findPageBypid(Integer pageNum, Integer pageSize, Long pid){
        PageResult result = itemCatService.findPage(pageNum,pageSize,pid);
        return result;
    }

    @RequestMapping("deletes")
    public Result deletes(@RequestBody Long[] ids){
        try {
            itemCatService.deleteByIds(ids);
            return new Result(true,"刪除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"刪除失败");
    }

    @RequestMapping("save")
    public Result save(@RequestBody TbItemCat entity, Long pid){
        try {
            itemCatService.saveOrUpdate(entity,pid);
            return new Result(true,"保存成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"保存失败");
    }

    @RequestMapping("findOne")
    public TbItemCat findOne(Long id){

        TbItemCat one = itemCatService.findOne(id);
        return one;

    }

}
